<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="/WEB-INF/jsp/common/common.jsp" %>
<script>

   function pageQuery( pageIndex ) {
	   $.ajax({
		   type : "POST",
		   url  : "${APP_PATH}/user/pageQuery.mvc",
		   data : {
			   pageno : pageIndex+1,
			   pagesize : 10
		   },
		   beforeSend : function() {
			   return true;
		   },
		   success : function( r ) {
			   if ( r.success ) {
				   // 渲染页面
				   var pageObj = r.data;
				   
				   var dataList  = pageObj.datas;
				   var totalsize = pageObj.totalsize;
				   var totalno   = pageObj.totalno;
				   
				   $("#totalsizeSpan").text(totalsize);
				   $("#totalnoSpan").text(totalno);
				   
				   var content = "";
				   $.each(dataList, function(index, user){
	                   content += '<tr class="odd">';
	                   content += '<td><input type="checkbox" value="'+user.id+'"/></td>';
	                   content += '<td>'+(index+1)+'</td>         ';
	                   content += '<td>'+user.loginacct+'</td>       ';
	                   content += '<td>'+user.username+'</td>       ';
	                   content += '<td>'+user.createtime+'</td>      ';
	                   content += '<td>'+user.email+'</td>           ';
	                   content += '<td>'+user.role+'</td>            ';
	                   content += '</tr>                            ';
				   });
				   
				   $("#userTBody").html(content);
				   
					//翻页显示
					$("#pagination").pagination(totalsize, {//总记录条数
						 init_query:false,
	                     callback: pageQuery,
	                     items_per_page:10, //每页显示多少条数据
	                     current_page:pageIndex,//当前页码
	                     link_to:"javascript:void(0)",//要保留超链接的样式，执行js代码，但是不跳转到任何资源
	                     num_display_entries:5,//默认显示几个页码
	                     next_text:"下一页",
	                     next_show_always:true,//如果没有下一页是否显示按钮
	                     prev_text:"上一页",
	                     prev_show_always:true,
	                     num_edge_entries:2,//页码多的时候，用...省略
	                     ellipse_text:"..."
	                 });
			   } else {
				   alert("用户信息分页查询失败");
			   }
		   }
	   });
   }
   
   $(document).ready(function(){
	   $("#insertBtn").click(function(){
		   window.location.href = "${APP_PATH}/user/add.mvc";
	   });
	   
	   $("#updateBtn").click(function(){
		   // 获取用户复选框的选择数量
		   var userBoxes = $("#userTBody input:checked");
		   if ( userBoxes.length == 0 ) {
			   alert("请选择需要修改的用户信息");
		   } else if ( userBoxes.length > 1 ) {
			   alert("只能选择一条用户信息进行修改");
		   } else {
			   window.location.href = "${APP_PATH}/user/edit.mvc?id="+$(userBoxes[0]).val();
		   }
	   });
	   
	   pageQuery(0);
   });

</script>
</head>

<body>
<table  border="0" cellpadding="0" cellspacing="0" class="table_border">
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_right">
      <tr>
        <td width="25" height="26" align="right"><img src="../images/ico_location.gif" width="16" height="15" /></td>
        <td><strong>位置：</strong>首页&gt;权限管理&gt;用户维护</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" class="table_padding">
      <tr>
        <td align="center">	
		<table  border="0" cellpadding="0" cellspacing="0" class="table_border">
          <tr>
            <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_right">
              <tr>
                <td height="26" align="right"><span class="font_right">
                  <input type="button" id="insertBtn" value="新增" />
                  <input type="button" id="deleteBtn" value="删除" />
                  <input type="button" id="updateBtn" value="修改"/>
                </span></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="122"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="center"><table border="0" cellpadding="0" cellspacing="0" id="box_num_table2" class="box_num_table">
                  <thead>
                    <tr>
                      <td width="8%"><input type="checkbox"/></td>
                      <td width="7%">序号</td>
                      <td width="12%">登录帐号</td>
                      <td width="11%">用户姓名</td>
                      <td width="12%">创建时间</td>
                      <td width="11%">邮箱</td>
                      <td width="11%">角色</td>
                      </tr>
                  </thead>
                  <tbody id="userTBody">
                  <%--
                  <!-- 
                     <c:forEach items="${userPage.datas}" var="user" varStatus="status">
	                    <tr class="odd">
	                      <td><input type="checkbox"/></td>
	                      <td>${status.count}</td>
	                      <td>${user.loginacct}</td>
	                      <td >${user.username}</td>
	                      <td>${user.createtime}</td>
	                      <td>${user.email}</td>
	                      <td>${user.role}</td>
	                      </tr>        
                     </c:forEach>
                     -->
                  --%>
                  </tbody>
                </table></td>
              </tr>
              <tr>
                <td><table width="100%" height="30" border="0" cellpadding="0" cellspacing="0" class="page_table">
                  <tr>
                    <td width="8%" class="font_left">数据:<span id="totalsizeSpan"></span>条</td>
                    <td width="12" class="font_left">第</td>
                    <td width="375" class="font_left"><input name="textfield2" type="text" size="2" maxlength="4" />
                      /:<span id="totalnoSpan"></span>页
                      <input type="image" border="0" align="absmiddle"  name="RedImg" src="../images/botton_page_to.png" onclick="this.form.submit()" /></td>
                    <td width="478" class="font_right"><div id="pagination"></div></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  </form>
</table>
</body>
</html>
